/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.swin.swinvehicle.bookingtype;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Administrator
 */
@Stateless
public class BookingTypeManagerBean implements BookingTypeManagerRemote {

    @PersistenceContext
    private EntityManager em;

    public List<BookingTypeTO> getAllBookingTypes() throws BookingTypeManagerException {
        try {
            List<BookingTypeTO> results = new ArrayList<BookingTypeTO>();
            Query allBookingTypesQuery = this.em.createNamedQuery("findAllBookingTypes");
            List dbResults = allBookingTypesQuery.getResultList();
            for (int i = 0; i < dbResults.size(); i++) {
                BookingTypeEntity bt = (BookingTypeEntity) dbResults.get(i);
                results.add(bt.getData());
            }
            return results;
        } catch (Exception e) {
            throw new BookingTypeManagerException("Cannot get all booking types", e);
        }
    }
}
